from cashier.models import CashierLoanDetails


# 存款利息计算公式 存款利率 / 360 / 100 * 保证金 * 存款天数
def get_interest_by_CashierLoanDetails_model(model):
    """计算存款利息"""
    # model = CashierLoanDetails.objects.get(id=1)
    if model.deposit_rate is not None and model.cash_deposit is not None and model.deposits_days is not None:
        return model.deposit_rate / 360 / 100 * model.cash_deposit * model.deposits_days
    else:
        return 0


# 存款利息计算公式 存款利率 / 360 / 100 * 保证金 * 存款天数
def get_interest(deposit_rate, cash_deposit, deposits_days):
    """计算存款利息"""
    return deposit_rate / 360 / 100 * cash_deposit * deposits_days


# 贴现成本计算公式 贴现利率 / 360 / 100 * 开票金额 * 存款天数
def get_discount_cost_by_CashierLoanDetails_model(model):
    """计算贴现成本"""
    # model = CashierLoanDetails.objects.get(id=1)
    if model.discount_rate is not None and model.invoice_amount is not None and model.deposits_days is not None:
        return model.discount_rate / 360 / 100 * model.invoice_amount * model.deposits_days
    else:
        return 0


# 贴现成本计算公式 贴现利率 / 360 / 100 * 开票金额 * 存款天数
def get_discount_cost(discount_rate, invoice_amount, deposits_days):
    """计算贴现成本"""
    return discount_rate / 360 / 100 * invoice_amount * deposits_days


# 成本计算公式 贴现成本 - 存款利息 + 开票手续费
def get_cost_by_CashierLoanDetails_model(model):
    """计算成本"""
    # model = CashierLoanDetails.objects.get(id=1)
    if model.discount_cost is not None and model.deposit_interest is not None and model.invoice_fee is not None:
        return model.discount_cost - model.deposit_interest + model.invoice_fee
    else:
        return 0
